<template>
  <div id="print">
    <div id="hidden">
      <div class="printin">
        <div id="chufanganallmsg">
          <span class="title">医疗处方单</span>
          <hr class="hr2" />
          <el-row :gutter="20">
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              科别：{{ patientInfo.subjectName }}</el-col
            >
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              门诊号：{{ patientInfo.id }}</el-col
            >
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              时间：{{ time }}</el-col
            >
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              姓名：{{ patientInfo.name }}</el-col
            >
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              年龄：{{ patientInfo.age }}</el-col
            >
            <el-col :span="8"
              ><div class="grid-content bg-purple"></div>
              性别：{{ patientInfo.sex ? patientInfo.sex : "未选择" }}</el-col
            >
          </el-row>

          <hr class="hr0" />
          <span
            v-for="(d, index) in chuafangdata.chufanlist"
            :key="index"
            style="font-size: 20px;"
          >
            {{ d.mediName }} ：{{ d.quantity }}{{ d.danwei }}
          </span>
        </div>
        <el-button
          class="flowR"
          type="primary"
          @click.stop="submitlast()"
          icon="el-icon-search"
          >提交病例</el-button
        >
        <!-- <el-button type="primary" @click.stop='print()' class="printbut" icon="el-icon-search">提交并打印病例</el-button> -->
        <el-button
          class="flowR"
          type="primary"
          @click.stop="openshow()"
          icon="el-icon-search"
          >修改</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import timenumtotimedata from "@/assets/js/timenumtotimedata.js";
import { mapActions, mapMutations, mapGetters } from "vuex";
export default {
  data() {
    return {
      time: "",
      lastdata: ""
    };
  },
  props: ["chuafangdata", "patientInfo"],
  mounted() {
    this.time = timenumtotimedata.timestampToTime(1620715071317, "yyyy-mm-dd");
    this.openshow();
    $(".printin").click(function(event) {
      event.stopPropagation();
    });
    $("#hidden").click(function(event) {
      //  event.stopPropagation();
      console.log(123);
      $("#hidden").hide();
    });
  },
  methods: {
    ...mapActions(["tongyong"]),

    openshow() {
      $("#hidden").hide();
    },
    async submitlast() {
      this.chuafangdata.personNo = this.patientInfo.personNo;
      this.chuafangdata.time = this.time;
      delete this.chuafangdata.count;
      for (let i = 0; i < this.chuafangdata.chufanlist.length; i++) {
        this.chuafangdata.chufanlist[i] = {
          mediNo: this.chuafangdata.chufanlist[i].mediNo,
          quantity: this.chuafangdata.chufanlist[i].quantity
        };
      }

      const res = await this["tongyong"]({
        name: "GET_ADDYAO",
        data: this.chuafangdata
      });  
      console.log(res);
      if(res.status==200){
        this.$message({
                showClose: true,
                message: '新增成功',
                type: 'success'
              });
         this.$router.push({
          name: "stu",
          query: {
            billno: this.chuafangdata.chufangnum
          }
        });  
      }else{
         this.$message({
                showClose: true,
                message: '新增成功',
                type: 'erro'
              });
      }
    }
  }
};
</script>

<style>
#hidden {
  width: 100%;
  height: 100%;
  background: red;
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.26);
  overflow-x: auto;
}
.printin {
  position: absolute;
  /* margin: 0 auto; */
  top: 50px;
  bottom: 50px;
  margin: 0 auto;
  left: 50%;
  margin-left: -450px;
  width: 900px;
  background-color: seashell;
  min-height: 1100px;
  padding: 10px;
}
#chufanganallmsg {
  padding: 20px 10px;
  height: 90%;
  margin-bottom: 20px;
  border: 1px solid #086da7;
}
.title {
  display: block;
  text-align: center;
  font-size: 50px;
  color: #05517e;
}
.hr0 {
  height: 1px;
  border: none;
  border-top: 1px dashed #086da7;
  margin: 10px 0;
}
.hr1 {
  height: 1px;
  border: none;
  border-top: 1px solid #086da7;
  margin: 10px 0;
}
.hr2 {
  height: 3px;
  border: none;
  border-top: 3px double #086da7;
  margin: 10px 0;
}
.hr3 {
  height: 5px;
  border: none;
  border-top: 5px ridge #086da7;
  margin: 10px 0;
}
.hr4 {
  height: 10px;
  border: none;
  border-top: 10px groove #086da7;
  margin: 10px 0;
}
.el-button + .el-button {
  margin: 0 10px;
}
.el-col {
  font-size: 25px;
}
</style>
